<template>
  <div class="register">
    <div>注册页</div>
    <input type="text" v-model="formData.phone" placeholder="输入手机号" style="padding-left:20px">
    <input type="password" v-model="formData.pass" placeholder="输入密码" style="padding-left:20px">
    <input type="password" v-model="formData.checkpass" placeholder="输入确认密码" style="padding-left:20px">
    <input type="submit" @click="register" value="注册" class="btn">
  </div>
</template>

<script>
import { user_register } from '@/utils/api';
export default {
  data(){
    return {
      formData:{
        phone:'',
        pass:'',
        checkpass:''
      }
    }
  },
  methods:{
    register(){
     if(/^1[3-9]\d{9}$/.test(this.formData.phone)==false){
      alert('请输入合法的手机号');
    }else if(!this.formData.pass || !this.formData.checkpass){
      alert('请输入密码/确认密码');
    }else if(this.formData.pass!==this.formData.checkpass){
      alert('密码和确认密码不一致');
    }else{
        user_register({phone:this.formData.phone,pass:this.formData.pass}).then((res)=>{ 
        alert(res.data.msg) ; 
      })
    }
    }
  }
}
</script>

<style>
.register div{
  font-size: 16px;
  font-weight: bold;
  text-align: center;
  margin-top: 40px;
}
.register input{
  margin-left: 70px;
  height: 30px;
  margin-top: 10px;
  background-color: #E3E4E5;
  border: none;
  border-radius: 30px;
  width: 240px;
}
.register .btn{
  background-color: burlywood;
  text-align: center;
}
</style>